const get_wx_login = '/user/weixin/wxLogin' // 微信用户登陆
const post_update_user = '/user/weixin/auth/updateUser' // 更新用户信息


/** 首页 **/
const get_sku_list = '/shop/home/getskuList'

const get_sort_list = '/shop/home/getsortList'

const get_common_sku = '/shop/home/getCommonSku'

/** 广场 **/
const get_square_navigation = '/shop/square/getNavigation'

const get_page_square_records = '/shop/square/getRecordList'

const get_comment_list = '/shop/square/listComment'

const click_like = '/shop/square/like'

const send_comment = '/shop/square/sendComment'

const find_chidren_comment = '/shop/square/findChidrenComment'


/** 海鲜市场 **/
const list_hot_topic = '/shop/market/listHotTopic'

const list_topic_rankdetail = '/shop/market/getHotRankDetail'

const list_topic_sku = '/shop/market/listTopicSku'

const get_relative_topic = '/shop/market/getRelativeTopic'

const get_topic_detail = '/shop/market/marketDetail/getTopicDetail'

const get_skuList_innerSort = '/shop/market/marketDetail/getSkuListByInnerSort'

const get_comment_sku = '/shop/market/marketDetail/getSkuComment'

const like_comment_click = '/shop/market/marketDetail/likeCommentClick'

const marketDetail_publish_comment = '/shop/market/marketDetail/publishComment'

const get_vote = '/shop/market/getVote'

const vote_click = '/shop/market/voteClick'





/** 聊天 **/
const list_message = '/chat/listFriendMessage'

const add_friend = '/chat/addFriend'

const find_new_list = '/chat/findNewsList'

/** 发布 **/
const get_all_category = '/shop/publish/getCategoryAllTree'





const install = (Vue, vm) => {
	/*---------------------------------------------------------
		用户登陆
	---------------------------------------------------------*/
	// 微信用户登陆
	const getWxLogin = (o) => vm.$u.get(get_wx_login + `/${o.code}`, {
		showLoading: false
	})
	// 更新用户信息
	const postUpdateUser = (o) => vm.$u.post(post_update_user, {
		...o,
		showLoading: false
	})

	/*---------------------------------------------------------
			首页数据以及搜索页
		---------------------------------------------------------*/

	const getskuList = (o) => {
		const {
			page,
			limit,
			form
		} = o;
		const params = {
			categoryId: form.categoryId,
			skuType: form.skuType,
			keyword: form.keyword,
		};

		// 删除不存在的参数
		for (let key in params) {
			if (params[key] === undefined) {
				delete params[key];
			}
		}

		return vm.$u.get(get_sku_list + `/${page}/${limit}`, params);
	};

	const getsortList = () => vm.$u.get(get_sort_list)

	const getCommonSku = (form)=> vm.$u.post(get_common_sku,form)
	
	const getHotTopic = ()=>vm.$u.get(list_hot_topic)
	
	const getTopicRankDetail = ()=>vm.$u.get(list_topic_rankdetail)
	
	const getTopicSku= (form)=>vm.$u.post(list_topic_sku,form)
	
	const getRelativeTopic = (form) =>vm.$u.post(get_relative_topic,form)
	
	const getVote= (form)=>vm.$u.post(get_vote,form)
	
	const voteClick= (form)=>vm.$u.post(vote_click,form)
	
	const getTopicDetail= (form)=>vm.$u.post(get_topic_detail,form)
	
	const getSkuListByInnerSort= (form)=>vm.$u.post(get_skuList_innerSort,form)
	
	const getMarketSkuComment= (form)=>vm.$u.post(get_comment_sku,form)
	
	
	const likeCommentClick= (form)=>vm.$u.post(like_comment_click,form)
	
	const marketDetailPublishComment= (form)=>vm.$u.post(marketDetail_publish_comment,form)
	
	
	
	/*---------------------------------------------------------
			发布
		---------------------------------------------------------*/
		//根据一级分类拿到后面的分类
	const getCategoryAllTree = () => vm.$u.get(get_all_category)
	//根据
	

	/*---------------------------------------------------------
			广场数据，评论也
		---------------------------------------------------------*/

	const getSquareNavigation = () => vm.$u.get(get_square_navigation)

	const getPageSquareRecords = (form) => vm.$u.post(get_page_square_records, form)

	//查询评论根据communityid
	const getCommentByCommunityId = (form) => vm.$u.post(get_comment_list, form)

	//点赞
	const ClickLike = (form) => vm.$u.post(click_like, form)

	//发送评论
	const sendComment = (form) => vm.$u.post(send_comment, form)
	
	//根据查询子评论分页
	const findChidrenComment =(form) => vm.$u.post(find_chidren_comment, form)


	/*---------------------------------------------------------
			消息数据
		---------------------------------------------------------*/
		
		//查询用户消息
	const findMessage = (form) => vm.$u.post(list_message, form)
	
	//添加好友
	const addFriend = (form)=>vm.$u.post(add_friend, form)
	
	//查询消息列表
	const findNewsList = ()=>vm.$u.post(find_new_list)
	
	


	vm.$u.api = {
		getWxLogin,
		postUpdateUser,
		getskuList,
		getsortList,
		getSquareNavigation,
		getPageSquareRecords,
		getCommentByCommunityId,
		ClickLike,
		sendComment,
		findChidrenComment,
		getCommonSku,
		findMessage,
		addFriend,
		findNewsList,
		getHotTopic,
		getTopicRankDetail,
		getTopicSku,
		getVote,
		voteClick,
		getRelativeTopic,
		getTopicDetail,
		getSkuListByInnerSort,
		getMarketSkuComment,
		likeCommentClick,
		marketDetailPublishComment,
		getCategoryAllTree
	};
}



export default {
	install
}